export interface Rule {
  rule: RegExp
  msg: string
}

export interface FormRule {
  // 姓名
  name: Rule[]
  // 地址
  address: Rule[]
  // 用户名
  username: Rule[]
  // 密码
  password: Rule[]
  // 手机号
  mobile: Rule[]
  // 邮政编码
  postalCode: Rule[]
  // 地址标签
  addressTags: Rule[]
  // 验证码
  code: Rule[]
}

// 表单校验规则
export let formRule: FormRule = {
  name: [
    {rule: /.+/, msg: '姓名不能为空'}
  ],
  address: [
    {rule: /.+/, msg: '地址不能为空'}
  ],
  username: [
    {rule: /.+/, msg: '用户名不能为空'},
    {rule: /^[a-zA-Z].{5,19}$/, msg: '字母开头且6-20字符'}
  ],
  password: [
    {rule: /.+/, msg: '密码不能为空'},
    {rule: /^.{6,24}$/, msg: '密码6-24字符'}
  ],
  mobile: [
    {rule: /.+/, msg: '手机号不能为空'},
    {rule: /^1[3-9]\d{9}$/, msg: '手机号格式有误'}
  ],
  postalCode: [
    {rule: /.+/, msg: '邮政编码不能为空'},
    {rule: /^\d{6}$/, msg: '邮政编码格式有误'}
  ],
  addressTags: [
    {rule: /.+/, msg: '地址标签不能为空'}
  ],
  code: [
    {rule: /.+/, msg: '验证码不能为空'},
    {rule: /^.{6}$/, msg: '验证码为6位字符'}
  ]
}